<template>
	<view class="index">
		<uni-swipe-action>
			<uni-swipe-action-item v-for="(item, index) in introduces" :key="item.introduceId" :right-options="options"
				@click="onClick($event,item)">
				<view class="culture" @click="to(item.introduceId)">
					<view class="images">
						<image :src="item.image"></image>
					</view>
					<text class="title">
						{{ item.title }}
					</text>
				</view>
			</uni-swipe-action-item>
		</uni-swipe-action>
	</view>
</template>

<script>
	import store from '@/store/index.js'
	import {
		mapState,
		mapMutations,
		mapActions,
		mapGetters
	} from 'vuex'

	export default {
		name: "introduce",
		data() {
			return {
				options: [
					// {
					// 	text: '编辑',
					// 	style: {
					// 		backgroundColor: '#007aff'
					// 	}
					// },
					{
						text: '删除',
						style: {
							backgroundColor: '#dd524d'
						}
					}
				]
			}
		},

		methods: {
			...mapMutations('course', ['getIntroduces']),
			onClick(e, item) {
				console.log(e, item)
				// if (e.index == 0) {
				// 	console.log(0)
				// }
				if (e.index == 0) {
					uni.request({
						url: 'http://localhost:3000/course/delete',
						method: 'post',
						data: [item, "introduce"],
						success: (res) => {
							console.log("删除数据：", res);
							this.getIntroduces()
						},
						fail: (res) => {
							console.log(res)
						}
					})
				}
			},
			to(e) {
				// console.log(e);
				uni.navigateTo({
					url: `/pages/index/introduce-detail/introduce-detail?id=${e}`,
				});
			},
		},
		computed: {
			...mapState('course', ['introduces']),
		},
		created() {
			if (!this.introduces.length) {
				this.getIntroduces()
			}

		}

	};
</script>

<style lang="scss" scoped>
	.culture {
		width: 90vw;
		margin: 0 auto;
		display: flex;
		//background-color: indianred;
		margin-bottom: 20rpx;
		padding-bottom: 15rpx;
		border-bottom: 3rpx solid (223, 226, 229);
	}

	.images {
		width: 40vw;
		height: 30vw;
		background-color: bisque;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	image {
		width: 36vw;
		height: 27vw;
		mode: widthFix;
		border-radius: 2vw;
	}
</style>